<template>
  <div class="app-container flex-col minH">
    <div class="topline w100p bgwhite ptb20 radius10 pl10 pr20 justify-between">
      <div>
        <el-input v-model="levelname" style="width: 280px" placeholder="搜尋等級名稱..." :prefix-icon="Search" class="search" />


      </div>
      <div>
        <el-button class="btn2" @click="getLevelList()">查詢</el-button>
        <el-button class="btn1" @click="reset()">重置</el-button>
      </div>
    </div>
    <div class="mt15 radius10 hidden pb15 flex1 bgwhite  flex-col w100p">
      <div class="flex1 w100p ">
        <el-table :data="tableData" style="width: 100%" cell-class-name="tbcell" header-cell-class-name="hdcell">

          <el-table-column prop="levelid" label="等級" width="80" />
          <el-table-column prop="levelname" label="等級名稱" width="120" />
          <el-table-column prop="level_up" label="消費次數" width="120" />
          <el-table-column prop="bili" label="消費折扣" width="120" />
          <el-table-column prop="thumb" label="標識" width="80">
            <template #default="scope">
              <el-image style="width: 50px; height: 50px" :src="scope.row.thumb" fit="cover" />
            </template>
          </el-table-column>
          <el-table-column prop="bj_image" label="背景图" width="100">
            <template #default="scope">
              <el-image style="width: 50px; height: 50px" :src="scope.row.bj_image" fit="cover" />
            </template>
          </el-table-column>
          <el-table-column prop="tips" label="説明" min-width="200" />
          <el-table-column prop="equity" label="權益" width="180" />
          <el-table-column prop="created_at" label="創建時間" width="180" />
          <el-table-column prop="updated_at" label="創建時間" sortable width="180" />

          <el-table-column prop="" label="操作" width="80" fixed="right">
            <template #default="scope">
              <div class=" pointer" @click="edit(scope.row)">編輯</div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class=" mrauto plr20 mt15">
        <el-button class="btn2" @click="toAdd()">新增</el-button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { Search } from '@element-plus/icons-vue'
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router';
import { levelList } from '@/api/level.js'
onMounted(() => {
  getLevelList()
})

// 后台充值记录
const getLevelList = () => {
  levelList({
    levelname: levelname.value
  }).then((res) => {
    console.log('后台充值记录', res)
    tableData.value = res.data.data
    total.value = res.data.total
  })
}
const reset = () => {
  levelname.value = ''
  getLevelList()
}
const levelname = ref('')
const dialogTableVisible = ref(false)

const tableData = ref([])
const tableRowClassName = () => {
  return 'tbrow'
}
const currentPage = ref(1)
const total = ref(0)
const handleSizeChange = (val) => {
  console.log(`${val} items per page`)
}
const handleCurrentChange = (val) => {
  console.log(`current page: ${val}`)
}
const router = useRouter()
const toAdd = () => {
  console.log(router)
  router.push({ path: 'levelAdd' })
}
const edit = (row) => {

  router.push({ path: 'levelEdit', query: row })
}
</script>

<style lang="scss" scoped>
.search {
  overflow: hidden;
  border-radius: 10px !important;
  // padding: 5px 0px;
}
</style>
<style></style>
